<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="/css/jquery.terminal.css" rel="stylesheet">
        <script src="/js/jquery-1.8.2.min.js"></script>
        <script src="/js/jquery.terminal-0.4.21.min.js"></script>
    </head>
    <body>
        <div id="term_demo"></div>
        <script>
        function battle(data, term)
        {
            term.echo(data.person.message);

            if( data.enemies_dead ){
                term.echo('Все враги откинулись');
                return;
            }
            
            var enemies = data.enemies;
            for(var id in enemies){
                term.echo(enemies[id].message);
            }

        }

        jQuery(function($, undefined) {
            $('#term_demo').terminal(function(command, term) {
                $.ajax({
                    'url': '/tests/battle.php',
                    'data': { 'command': command },
                    'dataType': 'json',
                    'success': function(data){
                        if( command == 'punch' ){
                            battle(data, term);
                        }
                        else
                            term.echo(data.message);
                    }
                });

            }, {
            greetings: 'Javascript Interpreter',
            name: 'js_demo',
            height: 200,
            prompt: 'js>'});
        });
        </script>
    </body>
</html>
